using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.Design;
using System.Security.Policy;
using System.Text;
using System.Windows.Media;
using System.Xml.Linq;

namespace RRX.Xml.ProjectTree
{
    public class ItemProjectTreeLoopSystem : INotifyPropertyChanged, IItemProjectTree
    {

        public ItemProjectTreeLoopSystem() {}


        // ---------- Properties ----------
        private string name { get; set; } = "Loop-System";
        public string Name
        {
            get => name;
            set
            {
                name = value;
                OnPropertyChanged("Name");
            }
        }

        private string functionGroup { get; set; } = "10";
        public string FunctionGroup
        {
            get => functionGroup;
            set
            {
                functionGroup = value;
                OnPropertyChanged("FunctionGroup");
            }
        }





        // ---------- Basic ----------
        private ObservableCollection<IItemProjectTree> children { get; set; } = new ObservableCollection<IItemProjectTree>();
        public ObservableCollection<IItemProjectTree> Children
        {
            get => children;
            set
            {
                children = value;
                OnPropertyChanged("Children");
            }
        }



        // ---------- Functions ----------
        public IItemProjectTree Copy()
        {
            ItemProjectTreeLoopSystem copy = new ItemProjectTreeLoopSystem();
            copy.name = name;
            copy.functionGroup = functionGroup;

            return copy;
        }

        public XElement Xml()
        {
            XElement xml = new XElement("syf");
            xml.SetAttributeValue("nam", name);
            xml.SetAttributeValue("prt", "1");
            xml.SetAttributeValue("fgr", functionGroup);

            foreach (IItemProjectTree item in Children)
            {
                xml.Add(item.Xml());
            }

            return xml;
        }


        // ---------- PropertyChanged ----------
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string name)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }
    }
}
